package com.jiukuaidao.zhulin.module.user.presenter;

import com.jiukuaidao.library.net.MyRetroCallBack;
import com.jiukuaidao.zhulin.api.ApiGetUserInfo;
import com.jiukuaidao.zhulin.data.TasksRepository;
import com.jiukuaidao.zhulin.entity.ApiUserInfo;
import com.jiukuaidao.zhulin.module.BasePresenter;
import com.jiukuaidao.zhulin.util.UserInfoUtil;
import com.jiukuaidao.zhulin.module.user.contract.MineContract;

/**
 * Author : PaiTaSuo
 * Date : 2016/5/25
 * Description :
 */
public class MinePresenter extends BasePresenter<MineContract.View, TasksRepository> implements MineContract.Prestener {
    public MinePresenter(TasksRepository repository, MineContract.View view) {
        super(repository, view);
    }

    @Override
    public void start() {
        loadData();
    }

    @Override
    public void loadData() {
        mRepository.loadData(new ApiGetUserInfo<>(new MyRetroCallBack<ApiUserInfo>() {
            @Override
            public void onSuccess(ApiUserInfo result, String errorCode, String msg) {
                UserInfoUtil.saveLoginInfo(result);
                mView.refreshView();
            }

            @Override
            public void onFail(ApiUserInfo result, String errorCode, String msg) {
//                mView.toast(msg);
            }

            @Override
            public void onError(Throwable t, int resCode, String msg) {
//                UserInfoUtil.cleanLoginInfo();
                mView.toast(resCode + "");
            }
        }));
    }
}
